package idiet.dao.hibernate;

import idiet.bean.CustomerNurseMeal;
import idiet.bean.CustomerNurseMealRecipe;

import java.util.List;

import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("customerNurseMealRecipeDao")
public class CustomerNurseMealRecipeDao extends BaseDao {
	public CustomerNurseMealRecipe getCustomerNurseMealRecipeById(int customerNurseMealRecipeId){
		return (CustomerNurseMealRecipe) this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMealRecipe.class)
				.add(Restrictions.eq("id", customerNurseMealRecipeId))
				.uniqueResult();
	}
	public CustomerNurseMealRecipe getCustomerNurseMealRecipesByTableName(String name){
		return (CustomerNurseMealRecipe) this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMealRecipe.class)
				.add(Restrictions.like("tableName",name))
				.uniqueResult();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerNurseMealRecipe> getCustomerNurseMealRecipes(){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMealRecipe.class)
				.list();
	}
	@SuppressWarnings("unchecked")
	public List<CustomerNurseMealRecipe> getCustomerNurseMealRecipesByCustomerNurseMeal(CustomerNurseMeal nurseMeal){
		return this.sessionFactory
				.getCurrentSession()
				.createCriteria(CustomerNurseMealRecipe.class)
				.add(Restrictions.eq("customerNurseMeal", nurseMeal))
				.list();
	}
	public void createCustomerNurseMealRecipe(CustomerNurseMealRecipe customerNurseMealRecipe){
		this.sessionFactory
		.getCurrentSession()
		.save(customerNurseMealRecipe);
	}
	public void updateCustomerNurseMealRecipe(CustomerNurseMealRecipe customerNurseMealRecipe){
		this.sessionFactory
		.getCurrentSession()
		.update(customerNurseMealRecipe);
	}
	public void deleteCustomerNurseMealRecipe(CustomerNurseMealRecipe customerNurseMealRecipe){
		this.sessionFactory
		.getCurrentSession()
		.delete(customerNurseMealRecipe);
	}
}
